package com.lxs.travel.route.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lxs.travel.core.service.impl.CrudServiceImpl;
import com.lxs.travel.route.dao.RouteImgDao;
import com.lxs.travel.route.po.Route;
import com.lxs.travel.route.po.RouteImg;
import com.lxs.travel.route.service.IRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RouteServiceImpl extends CrudServiceImpl<Route> implements IRouteService {

    @Autowired
    private RouteImgDao imgDao;

    @Override
    @Transactional(readOnly = false)
    public boolean saveOrUpdate(Route entity) {
        boolean result = super.saveOrUpdate(entity); //保存线路

        //根据线路id，删除线路的详细图片列表
        imgDao.delete(Wrappers.<RouteImg>lambdaQuery().eq(RouteImg::getRid, entity.getId()));

        //添加线路详细图片列表
        for (int i=0; i<entity.getBigImgList().size(); i++) {
            RouteImg img = new RouteImg();
            img.setRid(entity.getId());
            img.setBigPic(entity.getBigImgList().get(i));
            img.setSmallPic(entity.getSmallImgList().get(i));
            imgDao.insert(img);
        }

        return result;

    }



}
